import sys
sys.path.append(r"/data/finance.Source/collectionData/utils")

import sqlutils

connection = sqlutils.connect(dbname='futures')
file_path = '../static/20190124/dc/dc_20190117/a1903_20190117.csv'

connection = sqlutils.connect(dbname='futures')
try:
    with connection.cursor() as cursor:
        sql = "INSERT INTO `dc_tickkz` (`MarketCode`,`ContractCode`,`Time`,`NewPrice`,`OpenInt`,`Increment`,`Turnover`,`Volume`,`OpenVol`,`CloseVol`,`Type`,`Direction`,`BP1`,`SP1`,`BV1`,`SV1`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        def openfile(file_path):
            line_nu = 0
            with open(file_path,'r',encoding='gbk') as file_object:
                for line in file_object:
                    if line_nu > 0:
                        print(line)
                        cursor.execute(sql,(line))
                    line_nu += 1
    connection.commit()
finally:
    connection.close()